using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Adi_Game
{
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        #region Class Variables
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        SpriteFont font,
                   menu;

        bool isPause;

        int screenHeight,
            screenWidth,
            enemyTime,
            goodiesTime,
            fireTime,
            state,
            level,
            downElapsed,
            spaceElapsed,
            upElapsed;
            
        
        float pElapsed,
              pTime;


        tribalVariables tribal,
                        tribalMenu;
        spear spear;
        enemyTexture enemy;
        List<enemyBase> enemyList;
        List<Goddies> goodiesList;
        Map[] map;

        background backgrnd1,
                   backgrnd2,
                   backMenu,
                   instr,
                   about;

        Texture2D tile,
                  outline,
                  plank,
                  coin,
                  arrow;

        Rectangle outlineR,
                  plankR,
                  goodRect;

        #endregion

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        public void initVars()
        {
            tribal = new tribalVariables();
            tribalMenu = new tribalVariables();
            spear = new spear();
            enemy = new enemyTexture();
            enemyList = new List<enemyBase>();
            goodiesList = new List<Goddies>();
            outlineR = new Rectangle(250, 25, 304, 29);
            plankR = new Rectangle(252, 27, 300, 25);
            map = new Map[4];

            level = 0;
            state = 0; //0: Menu 1: Game
            isPause = false;

            map[0] = new Map("Content\\Maps\\map.txt");
            map[1] = new Map("Content\\Maps\\map2.txt");
            map[2] = new Map("Content\\Maps\\map3.txt");
            map[3] = new Map("Content\\Maps\\map4.txt");

            enemyTime = 0;
            goodiesTime = 0;
            fireTime = 0;
            pTime = 0;
            pElapsed = 0.30f;
            downElapsed = 0;
            spaceElapsed = 0;
            upElapsed = 0;

            graphics.PreferredBackBufferWidth = 1280;
            graphics.PreferredBackBufferHeight = 720;
            graphics.ApplyChanges();

            screenWidth = graphics.PreferredBackBufferWidth;
            screenHeight = graphics.PreferredBackBufferHeight;

            tribal.tribalPos = new Rectangle(300, screenHeight - (screenHeight / 6), 75, 75);
            tribalMenu.tribalPos = new Rectangle(screenWidth/2 - 225, (screenHeight / 2 - 125), 75, 75);
            spear.spearPos = new Rectangle(tribal.tribalPos.X + 15, tribal.tribalPos.Y + 45, 40, 15);
        }


        protected override void Initialize()
        {
            initVars();
            base.Initialize();
        }


        private void loadCharacterAssets()
        {
            backgrnd1 = new background(Content.Load<Texture2D>("Background\\background"), new Rectangle(0, 0, screenWidth, screenHeight));
            backgrnd2 = new background(Content.Load<Texture2D>("Background\\background2"), new Rectangle(screenWidth, 0, screenWidth, screenHeight));
            backMenu = new background(Content.Load<Texture2D>("Background\\backMenu"), new Rectangle(0, 0, screenWidth, screenHeight));
            instr = new background(Content.Load<Texture2D>("Background\\instr"), new Rectangle(0, 0, screenWidth, screenHeight));
            about = new background(Content.Load<Texture2D>("Background\\about"), new Rectangle(0, 0, screenWidth, screenHeight));

            plank = Content.Load<Texture2D>("Background\\plank");
            outline = Content.Load<Texture2D>("Background\\outline");

            coin = Content.Load<Texture2D>("Background\\gold");
            arrow = Content.Load<Texture2D>("Background\\arrow");
            goodRect = new Rectangle(0, 0, 50, 50);



            //Stationary State of the Tribal when he is Normal
            tribal.RunLs = Content.Load<Texture2D>("RunL\\RunLs");
            tribal.RunRs = Content.Load<Texture2D>("RunR\\RunRs");

            //Stationary State of the Tribal in Menu when he is Normal
            tribalMenu.RunRs = Content.Load<Texture2D>("RunR\\RunRs");

            //Stationary State of the Tribal when he is Hit
            tribal.AngryLs = Content.Load<Texture2D>("AngryL\\AngryLs");
            tribal.AngryRs = Content.Load<Texture2D>("AngryR\\AngryRs");

            //Spear Left and Right
            spear.spearl = Content.Load<Texture2D>("Weapon\\spearl");
            spear.spearr = Content.Load<Texture2D>("Weapon\\spearr");


            // Sprites for Walking Left
            for (int i = 0; i < 4; i++)
            {
                String fileName = "WalkL\\" + (i + 1).ToString();
                tribal.WalkL[i] = Content.Load<Texture2D>(fileName);
            }

            // Sprites for Walking Right
            for (int i = 0; i < 4; i++)
            {
                String fileName = "WalkR\\" + (i + 1).ToString();
                tribal.WalkR[i] = Content.Load<Texture2D>(fileName);
            }

            // Sprites for Running Left
            for (int i = 0; i < 14; i++)
            {
                String fileName = "RunL\\" + (i + 1).ToString();
                tribal.RunL[i] = Content.Load<Texture2D>(fileName);
            }

            // Sprites for Running Right
            for (int i = 0; i < 14; i++)
            {
                String fileName = "RunR\\" + (i + 1).ToString();
                tribal.RunR[i] = Content.Load<Texture2D>(fileName);
            }

            // Sprites for Angry Running Left
            for (int i = 0; i < 14; i++)
            {
                String fileName = "AngryL\\" + (i + 1).ToString();
                tribal.AngryL[i] = Content.Load<Texture2D>(fileName);
            }

            // Sprites for Angry Running Right
            for (int i = 0; i < 14; i++)
            {
                String fileName = "AngryR\\" + (i + 1).ToString();
                tribal.AngryR[i] = Content.Load<Texture2D>(fileName);
            }

            // Enemy Left Run
            for (int i = 0; i < 14; i++)
            {
                String fileName = "EnemyL\\" + (i + 1).ToString();
                enemy.EnemyL[i] = Content.Load<Texture2D>(fileName);
            }

            // Enemy Right Run
            for (int i = 0; i < 14; i++)
            {
                String fileName = "EnemyR\\" + (i + 1).ToString();
                enemy.EnemyR[i] = Content.Load<Texture2D>(fileName);
            }
        }

        
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Load Fonts
            font = Content.Load<SpriteFont>("Fonts\\disp");
            menu = Content.Load<SpriteFont>("Fonts\\menu");
           
            //Load backgrnd 
            tile = Content.Load<Texture2D>("Background\\tiles");

            //Load All Characters in the Scene
            loadCharacterAssets();
        }

        protected override void UnloadContent()
        {
        }


        protected override void Update(GameTime gameTime)
        {
            switch (state)
            {

                case 0:
                    {
                        #region Menu Keyboard Handling
                        if (Keyboard.GetState().IsKeyDown(Keys.Enter))
                        {
                            int x = tribalMenu.tribalPos.Y;
                            if (x == screenHeight / 2 - 125)
                            {
                                state = 1;
                            }

                            else if (x == (screenHeight / 2 - 125) + 75)
                            {
                                state = 3;
                            }

                            else if (x == (screenHeight / 2 - 125) + 150)
                            {
                                state = 5;
                            }

                            else if (x == (screenHeight / 2 - 125) + 225)
                            {
                                this.Exit();
                            }

                        }

                        if (Keyboard.GetState().IsKeyDown(Keys.Down))
                        {
                            downElapsed += gameTime.ElapsedGameTime.Milliseconds;
                            if (downElapsed >= 80)
                            {
                                tribalMenu.tribalPos.Y += 75;
                                if (tribalMenu.tribalPos.Y > ((screenHeight / 2 - 125) + 225))
                                {
                                    tribalMenu.tribalPos.Y = screenHeight / 2 - 125;
                                }
                                downElapsed = 0;
                            }
                        }

                        if (Keyboard.GetState().IsKeyDown(Keys.Up))
                        {
                            upElapsed += gameTime.ElapsedGameTime.Milliseconds;
                            if (upElapsed >= 80)
                            {
                                tribalMenu.tribalPos.Y -= 75;
                                if (tribalMenu.tribalPos.Y < (screenHeight/2 - 125))
                                {
                                    tribalMenu.tribalPos.Y = (screenHeight / 2 - 125) + 225;
                                }
                                upElapsed = 0;
                            }
                        }
                        #endregion

                    } break;

                case 1:
                    {
                        #region Case for The Game Running

                        #region Scrolling Background
                        pTime += (float)gameTime.ElapsedGameTime.TotalSeconds;

                        backgrnd1.backRect.X -= 5;
                        backgrnd2.backRect.X -= 5;

                        if (backgrnd1.backRect.X + backgrnd1.backgrnd.Width <= 0)
                        {
                            backgrnd1.backRect.X = backgrnd2.backRect.X + backgrnd2.backgrnd.Width;
                        }

                        if (backgrnd2.backRect.X + backgrnd2.backgrnd.Width <= 0)
                        {
                            backgrnd2.backRect.X = backgrnd1.backRect.X + backgrnd1.backgrnd.Width;
                        }

                        #endregion

                        #region Keyboard Controls

                        //Exiting game by pressing ESC  
                        if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                        {
                            state = 0;
                        }

                        //Getting Values from the Keyboard to see control the Tribal
                        tribal.upArrow = Keyboard.GetState().IsKeyDown(Keys.Up);
                        tribal.rightArrow = Keyboard.GetState().IsKeyDown(Keys.Right);
                        tribal.leftArrow = Keyboard.GetState().IsKeyDown(Keys.Left);

                        spaceElapsed += gameTime.ElapsedGameTime.Milliseconds;

                        if (spaceElapsed >= 60)
                        {
                            spear.isFired = Keyboard.GetState().IsKeyDown(Keys.Space);
                            if (!spear.shoot && spear.isFired && tribal.arrows > 0)
                            {
                                spear.shoot = true;
                                tribal.arrows--;
                            }

                            fireTime = 0;
                            spaceElapsed = 0;
                        }

                        #endregion

                        if (!isPause)
                        {
                            if (tribal.lives > 0)
                            {
                                #region Resetting Tribal Life
                                if (tribal.health == 0)
                                {
                                    tribal.lives--;
                                    tribal.health = 300;
                                    tribal.tribalPos.X = 300;
                                    tribal.tribalPos.Y = screenHeight - (screenHeight / 6);
                                    spear.spearPos.X = tribal.tribalPos.X + 15;
                                    spear.spearPos.Y = tribal.tribalPos.Y + 45;
                                }
                                #endregion

                                #region Did the Tribal Fall ?
                                tribal.fall = (tribal.tribalPos.X + 45) / 64;
                                if (map[level].tiles[tribal.fall] == '-' && tribal.tribalPos.Y == (screenHeight - (screenHeight / 6)))
                                {
                                    tribal.isFall = true;
                                }

                                #endregion

                                #region Jump Handling

                                if (tribal.upArrow && tribal.landed)
                                {
                                    tribal.jumped = true;
                                    tribal.jumpFlag = 1;
                                    tribal.landed = false;
                                }

                                if (tribal.jumped)
                                {

                                    if (tribal.isFall && tribal.tribalPos.Y > (screenHeight - (screenHeight / 6)))
                                    {
                                        tribal.jumped = false;
                                        tribal.landed = true;


                                        tribal.tribalPos.Y += 65;
                                        spear.spearPos.Y += 65;
                                        if (tribal.tribalPos.Y >= (screenHeight - 50))
                                        {
                                            tribal.isFall = false;
                                            tribal.lives--;
                                            tribal.health = 300;
                                            tribal.tribalPos.X = 300;
                                            tribal.tribalPos.Y = screenHeight - (screenHeight / 6);
                                            spear.spearPos.X = tribal.tribalPos.X + 15;
                                            spear.spearPos.Y = tribal.tribalPos.Y + 45;
                                        }

                                        if (!spear.shoot)
                                        {
                                            spear.spearPos.Y = tribal.tribalPos.Y + 45;
                                        }
                                    }

                                    else if (tribal.tribalPos.Y > (screenHeight - (screenHeight / 6)))
                                    {
                                        tribal.jumped = false;
                                        tribal.landed = true;
                                        tribal.tribalPos.Y = screenHeight - (screenHeight / 6);

                                        if (!spear.shoot)
                                        {
                                            spear.spearPos.Y = tribal.tribalPos.Y + 45;
                                        }
                                    }

                                    else if (tribal.jumpFlag == 1 && (tribal.tribalPos.Y >= screenHeight - (screenHeight / 3.2)))
                                    {

                                        tribal.tribalPos.Y -= 8;
                                        if (!spear.shoot)
                                        {
                                            spear.spearPos.Y -= 8;
                                        }

                                    }

                                    else
                                    {
                                        tribal.jumpFlag = 0;
                                        tribal.tribalPos.Y += 8;
                                        if (!spear.shoot)
                                        {
                                            spear.spearPos.Y += 8;
                                        }
                                    }
                                }

                                #endregion

                                #region Left and Right Arrow Motion
                                if (tribal.leftArrow)
                                {
                                    tribal.stat = -1;
                                    tribal.run = 0;
                                    tribal.maxFrame = 13;
                                    tribal.frameGap = 20.0;
                                    if (tribal.tribalPos.X >= 0)
                                    {
                                        tribal.tribalPos.X -= 4;
                                        if (!spear.shoot)
                                        {
                                            spear.spearPos.X -= 4;
                                        }

                                        if (tribal.isFall)
                                        {
                                            tribal.tribalPos.Y += 45;
                                            spear.spearPos.Y += 45;
                                            if (tribal.tribalPos.Y >= (screenHeight - 50))
                                            {
                                                tribal.isFall = false;
                                                tribal.lives--;
                                                tribal.health = 300;
                                                tribal.tribalPos.X = 300;
                                                tribal.tribalPos.Y = screenHeight - (screenHeight / 6);
                                                spear.spearPos.X = tribal.tribalPos.X + 15;
                                                spear.spearPos.Y = tribal.tribalPos.Y + 45;
                                            }

                                        }
                                    }
                                }

                                else if (tribal.rightArrow)
                                {
                                    tribal.stat = -1;
                                    tribal.run = 1;
                                    tribal.maxFrame = 13;
                                    tribal.frameGap = 20.0;
                                    if (tribal.tribalPos.X <= screenWidth - 50)
                                    {
                                        tribal.tribalPos.X += 4;
                                        if (!spear.shoot)
                                        {
                                            spear.spearPos.X += 4;
                                        }

                                        if (tribal.isFall)
                                        {
                                            tribal.tribalPos.Y += 45;
                                            spear.spearPos.Y += 45;
                                            if (tribal.tribalPos.Y >= (screenHeight - 50))
                                            {
                                                tribal.isFall = false;
                                                tribal.lives--;
                                                tribal.health = 300;
                                                tribal.tribalPos.X = 300;
                                                tribal.tribalPos.Y = screenHeight - (screenHeight / 6);
                                                spear.spearPos.X = tribal.tribalPos.X + 15;
                                                spear.spearPos.Y = tribal.tribalPos.Y + 45;
                                            }
                                        }

                                    }
                                }

                                else
                                {
                                    if (tribal.stat == -1)
                                    {
                                        tribal.stat = tribal.run;
                                    }
                                    tribal.run = -1;
                                }

                                #endregion

                                #region Frame Changing of the Tribal
                                if (tribal.prevFrameTime + tribal.frameGap <= gameTime.TotalGameTime.TotalMilliseconds)
                                {
                                    tribal.currFramId++;
                                    tribal.prevFrameTime = gameTime.TotalGameTime.TotalMilliseconds;
                                }

                                if (spear.isHit)
                                {
                                    if (tribal.angryTime + tribal.angryGap <= gameTime.TotalGameTime.TotalMilliseconds)
                                    {
                                        tribal.angryFrame = !tribal.angryFrame;
                                        tribal.angryTime = gameTime.TotalGameTime.TotalMilliseconds;
                                        if (tribal.hitTimes == 10)
                                        {
                                            tribal.hitTimes = 0;
                                            spear.isHit = false;
                                            tribal.angryFrame = false;
                                        }

                                        else
                                        {
                                            tribal.hitTimes++;
                                        }
                                    }

                                }


                                if (tribal.currFramId >= tribal.maxFrame)
                                {
                                    tribal.currFramId = 0;
                                }

                                #endregion

                                #region Enemy Randomized Movement and Collsion Detection

                                //Rate at which the enemy comes
                                enemyTime += gameTime.ElapsedGameTime.Milliseconds;

                                Random r = new Random();
                                int rand = r.Next(1500, 2500);

                                if (enemyTime >= rand)
                                {
                                    enemyTime = 0;
                                    enemyBase temp = new enemyBase();
                                    temp.enemyPos = new Rectangle(screenWidth, screenHeight - (screenHeight / 6), 75, 75);
                                    enemyList.Add(temp);
                                }


                                for (int i = 0; i < enemyList.Count; i++)
                                {
                                    int X = enemyList[i].enemyPos.X + 25;
                                    X = X / 64;

                                    if (X >= 19)
                                    {
                                        X = 19;
                                    }

                                    else if (X <= 0)
                                    {
                                        X = 0;
                                    }

                                    if (map[level].tiles[X] == '-')
                                    {
                                        enemyList[i].isFall = true;
                                        enemyList[i].jumped = true;
                                        enemyList[i].jumpFlag = 1;
                                        enemyList[i].landed = false;
                                    }



                                    if (enemyList[i].jumped)
                                    {
                                        if (enemyList[i].enemyPos.Y > (screenHeight - (screenHeight / 6)))
                                        {
                                            enemyList[i].jumped = false;
                                            enemyList[i].landed = true;
                                            enemyList[i].enemyPos.Y = screenHeight - (screenHeight / 6);
                                        }

                                        else if (enemyList[i].jumpFlag == 1 && (enemyList[i].enemyPos.Y >= screenHeight - (screenHeight / 3.2)))
                                        {
                                            enemyList[i].enemyPos.Y -= 8;
                                        }

                                        else
                                        {
                                            enemyList[i].jumpFlag = 0;
                                            enemyList[i].enemyPos.Y += 8;
                                        }
                                    }



                                    enemyList[i].enemyPos.X -= 4;

                                    if (spear.shoot && (Math.Abs((enemyList[i].enemyPos.Y + 45) - spear.spearPos.Y) <= 35) && (Math.Abs(enemyList[i].enemyPos.X - spear.spearPos.X) <= 10))
                                    {
                                        enemyList.RemoveAt(i);
                                        tribal.score += 30;
                                        spear.spearSide = -1;
                                        spear.shoot = false;
                                        spear.spearPos.X = tribal.tribalPos.X + 15;
                                        spear.spearPos.Y = tribal.tribalPos.Y + 45;
                                        continue;
                                    }

                                    if ((Math.Abs(enemyList[i].enemyPos.X - tribal.tribalPos.X) <= 60) && (Math.Abs(enemyList[i].enemyPos.Y - tribal.tribalPos.Y) <= 5))
                                    {
                                        enemyList.RemoveAt(i);
                                        tribal.health -= 25;
                                        spear.isHit = true;
                                        continue;
                                    }


                                    if (enemyList[i].perFrameTime + enemyList[i].frameGap <= gameTime.TotalGameTime.TotalMilliseconds)
                                    {
                                        enemyList[i].currFramId++;
                                        enemyList[i].perFrameTime = gameTime.TotalGameTime.TotalMilliseconds;
                                    }


                                    if (enemyList[i].currFramId >= enemyList[i].maxFrame)
                                    {
                                        enemyList[i].currFramId = 0;
                                    }


                                }


                                #endregion

                                #region Managing the Spear

                                if (spear.shoot)
                                {
                                    fireTime += gameTime.ElapsedGameTime.Milliseconds;
                                }


                                if (fireTime >= 200 && spear.isHit == false && spear.failHit == false)
                                {
                                    fireTime = 0;
                                    spear.failHit = true;
                                }

                                if (spear.shoot)
                                {
                                    if (spear.spearSide == -1 && tribal.run == 1)
                                    {
                                        spear.spearSide = 1;
                                    }

                                    else if (spear.spearSide == -1 && tribal.run == 0)
                                    {
                                        spear.spearSide = 0;
                                    }

                                }

                                if (spear.spearSide == 1)
                                {
                                    spear.spearPos.X += 5;
                                }

                                else if (spear.spearSide == 0)
                                {
                                    spear.spearPos.X -= 5;
                                }

                                else if (spear.shoot)
                                {
                                    spear.spearPos.X += 5;
                                    spear.spearSide = tribal.stat;
                                }


                                if ((spear.spearPos.X >= screenWidth) || (spear.spearPos.X <= -50) || spear.isHit || spear.failHit )
                                {
                                    spear.spearSide = -1;
                                    spear.shoot = false;
                                    spear.failHit = false;
                                    spear.spearPos.X = tribal.tribalPos.X + 15;
                                    spear.spearPos.Y = tribal.tribalPos.Y + 45;
                                }
                                #endregion

                                #region Random Coins/Arrows For Collection

                                goodiesTime += gameTime.ElapsedGameTime.Milliseconds;

                                Random r1 = new Random();
                                double rand1 = r1.Next(900, 2000);
                                int coa = r1.Next(0, 2);
                                if (goodiesTime >= rand1)
                                {
                                    goodiesTime = 0;
                                    Goddies temp = new Goddies();
                                    temp.type = coa;
                                    int lh = (int)(screenHeight / 3);
                                    int hh = (int)(screenHeight - screenHeight / 7);
                                    temp.pos = new Rectangle(r1.Next(0,screenWidth), lh +  r1.Next(lh,hh), 50, 50);
                                    if (tribal.arrows <= 5 && temp.type == 1)
                                    {
                                        goodiesList.Add(temp);
                                    }

                                    else if (temp.type == 0)
                                    {
                                        goodiesList.Add(temp);
                                    }
                                }

                                if (tribal.score >= 3000)
                                {
                                    state = 4;
                                }

                                for (int i = 0; i < goodiesList.Count; i++)
                                {
                                    if ((Math.Abs(tribal.tribalPos.X - goodiesList[i].pos.X) <= 55) && (Math.Abs((tribal.tribalPos.Y + 45) - goodiesList[i].pos.Y) <= 55))
                                    {
                                        if (goodiesList[i].type == 0)
                                        {
                                            tribal.score += 50;
                                        }

                                        else
                                        {
                                            tribal.arrows += 5;
                                        }

                                        goodiesList.RemoveAt(i);
                                    }
                                }

                                #endregion
                            }

                            else
                            {
                                state = 2;
                            }

                            if (pTime >= pElapsed)
                            {
                                if (Keyboard.GetState().IsKeyDown(Keys.P))
                                {
                                    isPause = true;
                                    pTime = 0;
                                }
                            }
                        }

                        else
                        {
                            if (pTime >= pElapsed)
                            {
                                if (Keyboard.GetState().IsKeyDown(Keys.P))
                                {
                                    isPause = false;
                                    pTime = 0;
                                }
                            }
                        }
                        #endregion
                    } break;

                    
                case 2:
                    {
                        #region Case for Game Over
                        if (Keyboard.GetState().IsKeyDown(Keys.Space))
                        {
                            initVars();
                            loadCharacterAssets();
                            state = 0;
                        }
                        #endregion
                    } break;

                case 3:
                    {
                        if (Keyboard.GetState().IsKeyDown(Keys.Back))
                        {
                            state = 0;
                        }
                    } break;

                case 4:
                    {
                        if (Keyboard.GetState().IsKeyDown(Keys.Space))
                        {
                            initVars();
                            loadCharacterAssets();
                            state = 0;
                        }
                    } break;
                case 5:
                    {
                        if (Keyboard.GetState().IsKeyDown(Keys.Back))
                        {
                            state = 0;
                        }
                    } break;

            }

            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            spriteBatch.Begin();



            #region Drawing Everything

            switch (state)
            {
                case 0:
                    {
                        backMenu.Draw(spriteBatch);
                        spriteBatch.Draw(tribalMenu.RunRs, tribalMenu.tribalPos, Color.White);
                        spriteBatch.DrawString(menu, "TRIBAL SURVIVAL", new Vector2(screenWidth / 2 - 175, 50), Color.Black);
                        spriteBatch.DrawString(menu, "Play Game", new Vector2(screenWidth / 2 - 150, (screenHeight/2 - 100)), Color.Brown);
                        spriteBatch.DrawString(menu, "Instructions", new Vector2(screenWidth / 2 - 150, (screenHeight / 2 - 100) + 75), Color.Brown);
                        spriteBatch.DrawString(menu, "Survival", new Vector2(screenWidth / 2 - 150, (screenHeight / 2 - 100) + 150), Color.Brown);
                        spriteBatch.DrawString(menu, "Exit", new Vector2(screenWidth / 2 - 150, (screenHeight / 2 - 100) + 225), Color.Brown);
                    } break;

                case 1:
                    {
                        backgrnd1.Draw(spriteBatch);
                        backgrnd2.Draw(spriteBatch);

                        if (isPause)
                        {
                            spriteBatch.DrawString(menu, "|| Paused", new Vector2(screenWidth / 2 - 50, screenHeight / 2), Color.Brown);
                        }

                        #region Drawing the Characters in Scene

                        if (tribal.run == 0)
                        {
                            if (tribal.angryFrame)
                            {
                                spriteBatch.Draw(tribal.AngryL[tribal.currFramId], tribal.tribalPos, Color.White);
                            }

                            else
                            {
                                spriteBatch.Draw(tribal.RunL[tribal.currFramId], tribal.tribalPos, Color.White);
                            }
                        }

                        else if (tribal.run == 1)
                        {
                            if (tribal.angryFrame)
                            {
                                spriteBatch.Draw(tribal.AngryR[tribal.currFramId], tribal.tribalPos, Color.White);
                            }

                            else
                            {
                                spriteBatch.Draw(tribal.RunR[tribal.currFramId], tribal.tribalPos, Color.White);
                            }
                        }

                        else
                        {

                            if (tribal.stat == 1)
                            {
                                if (tribal.angryFrame)
                                {
                                    spriteBatch.Draw(tribal.AngryRs, tribal.tribalPos, Color.White);
                                }

                                else
                                {
                                    spriteBatch.Draw(tribal.RunRs, tribal.tribalPos, Color.White);
                                }
                            }

                            else
                            {
                                if (tribal.angryFrame)
                                {
                                    spriteBatch.Draw(tribal.AngryLs, tribal.tribalPos, Color.White);
                                }

                                else
                                {
                                    spriteBatch.Draw(tribal.RunLs, tribal.tribalPos, Color.White);
                                }
                            }

                        }

                        if (spear.spearSide == 1)
                        {
                            spriteBatch.Draw(spear.spearr, spear.spearPos, Color.White);
                        }

                        else if (spear.spearSide == 0)
                        {
                            spriteBatch.Draw(spear.spearl, spear.spearPos, Color.White);
                        }

                        else if (tribal.run == 0 || tribal.stat == 0)
                        {
                            spriteBatch.Draw(spear.spearl, spear.spearPos, Color.White);
                        }

                        else
                        {
                            spriteBatch.Draw(spear.spearr, spear.spearPos, Color.White);
                        }

                        for (int i = 0; i < enemyList.Count; i++)
                        {
                            spriteBatch.Draw(enemy.EnemyL[enemyList[i].currFramId], enemyList[i].enemyPos, Color.White);
                        }

                        for (int i = 0; i < goodiesList.Count; i++)
                        {
                            goodRect.X = goodiesList[i].pos.X;
                            goodRect.Y = goodiesList[i].pos.Y;

                            if (goodiesList[i].type == 0)
                            {
                                spriteBatch.Draw(coin, goodRect, Color.White);
                            }

                            else
                            {
                                spriteBatch.Draw(arrow, goodRect, Color.White);
                            }

                        }


                        #endregion

                        map[level].DrawTiles(spriteBatch, tile);

                        spriteBatch.DrawString(font, "Tribal Health : ", new Vector2(50, 25), Color.Black);
                        spriteBatch.Draw(outline, outlineR, Color.White);
                        plankR.Width = tribal.health;
                        spriteBatch.Draw(plank, plankR, Color.White);

                        spriteBatch.DrawString(font, "Score : ", new Vector2(50, 60), Color.Black);
                        spriteBatch.DrawString(font, tribal.score.ToString(), new Vector2(250, 60), Color.Black);
                        spriteBatch.DrawString(font, "/ 3000", new Vector2(300, 60), Color.Black);
                        spriteBatch.DrawString(font, "Tribal Lives : ", new Vector2(50, 95), Color.Black);
                        spriteBatch.DrawString(font, "P : Pause/Unpause", new Vector2(screenWidth - 300, 25), Color.Black);
                        spriteBatch.DrawString(font, "Esc : Main Menu", new Vector2(screenWidth - 290, 50), Color.Black);

                        for (int i = 0; i < tribal.lives; i++)
                        {
                            spriteBatch.Draw(tribal.RunRs, new Rectangle(250 + (50 * i), 85, 50, 50), Color.White);
                        }

                        spriteBatch.DrawString(font, "Arrows Left : ", new Vector2(50, 150), Color.Black);
                        spriteBatch.DrawString(font, tribal.arrows.ToString(), new Vector2(250, 150), Color.Black);




                    } break;

                case 2:
                    {
                        backgrnd1.Draw(spriteBatch);
                        backgrnd2.Draw(spriteBatch);
                        spriteBatch.DrawString(menu, "GAME OVER", new Vector2(screenWidth / 2 - 100, screenHeight / 2 - 75), Color.Brown);
                        spriteBatch.DrawString(font, "Press Space for Main Menu", new Vector2(screenWidth / 2 - 110, screenHeight / 2), Color.Black);

                    } break;

                case 3:
                    {
                        instr.Draw(spriteBatch);
                        spriteBatch.DrawString(menu, "INSTRUCTIONS", new Vector2(screenWidth / 2 - 150, 50), Color.Black);
                        spriteBatch.DrawString(menu, "Jump Up", new Vector2(screenWidth / 2 - 110, (screenHeight / 2 - 175)), Color.Brown);
                        spriteBatch.DrawString(menu, "Left and Right Locomotion", new Vector2(screenWidth / 2 - 110, (screenHeight / 2 - 100)), Color.Brown);
                        spriteBatch.DrawString(menu, "Shoot Arrows", new Vector2(screenWidth / 2 - 110, (screenHeight / 2 - 25)), Color.Brown);
                        spriteBatch.DrawString(menu, "Pause / Unpause", new Vector2(screenWidth / 2 - 110, (screenHeight / 2 + 50)), Color.Brown);
                        spriteBatch.DrawString(font, "Backspace to Continue", new Vector2(screenWidth / 2 - 110, (screenHeight / 2 + 175)), Color.Black);
                    } break;

                case 4:
                    {
                        backgrnd1.Draw(spriteBatch);
                        backgrnd2.Draw(spriteBatch);
                        spriteBatch.DrawString(menu, "YOU WIN", new Vector2(screenWidth / 2 - 130, screenHeight / 2 - 75), Color.Brown);
                        spriteBatch.DrawString(font, "Press Space for Main Menu", new Vector2(screenWidth / 2 - 140, screenHeight / 2), Color.Black);

                    } break;

                case 5:
                    {
                        about.Draw(spriteBatch);
                        spriteBatch.DrawString(menu, "ABOUT THE GAME", new Vector2(screenWidth / 2 - 180, 50), Color.Black);
                        spriteBatch.DrawString(font, "Backspace to Continue", new Vector2(screenWidth / 2 + 150, (screenHeight / 2 + 175)), Color.Black);

                    } break;

            }


            #endregion

            spriteBatch.End();


            base.Draw(gameTime);
        }
    }
}
